from cold_start_analyzer.base_analyzer import BaseAnalyzer
from cold_start_analyzer.consts import NOT_AVAILABLE


class Phase1AppStart(BaseAnalyzer):
    description = "桌面启动应用: 从BundleMgrProxy::QueryAbilityInfo到发起到HandleLaunchApplication开始"
    def get_result(self):
        """
        起点： SceneBoard-OS_SceneSession
        H:virtual bool OHOS::AppExecFwk::BundleMgrProxy::QueryAbilityInfo
        终点： app_thread
        H:void OHOS::AppExecFwk::MainThread::HandleLaunchApplication
        """
        if 'Phase1All' not in self.context:
            return NOT_AVAILABLE
        return self.context['Phase1All']['end_ts'] - self.context['Phase1All']['query_ability_info']